import {getDictByTypeValue, getDictsByType} from "./sys-dic-utils";
import Vue from 'vue'

export function sysDicRenderByType(type) {

    return (v, record, index) => {
        var d = getDictByTypeValue(type, v);
        if(d){
            return d.label;
        }else{
            return ""
        }
    }
}
export function formatTake(take){
    var newTake;
    if (take < 10) { //  补全公里桩
        newTake = "000" + String(take);
    } else if (take < 100) {
        newTake = "00" + String(take);
    } else if (take < 1000) {
        newTake = "0" + String(take);
    } else {
        newTake = String(take);
    }
    return newTake;

}



export function saveAs(obj, fileName) {
    var tmpa = document.createElement("a");
    tmpa.download = fileName || "下载";
    tmpa.href = URL.createObjectURL(obj);
    tmpa.click();
    setTimeout(function () {
        URL.revokeObjectURL(obj);
    }, 100);
}

export function getCharCol(n) {
    let temCol = '',
        s = '',
        m = 0
    while (n > 0) {
        m = n % 26 + 1
        s = String.fromCharCode(m + 64) + s
        n = (n - m) / 26
    }
    return s
}

export function s2ab(s) {
    if (typeof ArrayBuffer !== 'undefined') {
        var buf = new ArrayBuffer(s.length);
        var view = new Uint8Array(buf);
        for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
        return buf;
    } else {
        var buf = new Array(s.length);
        for (var i = 0; i != s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
        return buf;
    }
}
